package org.example.threadobjectclasscommonmethods;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @description: 多线程异常处理器
 * @author: MoodAir
 * @Date: 2020/6/9 0009 22:28
 */
public class UncaughtException implements UncaughtExceptionHandler {

  private final String name;

  public UncaughtException(String name) {
    this.name = name;
  }

  @Override
  public void uncaughtException(Thread t, Throwable e) {
    Logger log = Logger.getAnonymousLogger();
    log.log(Level.WARNING, "线程异常，结束了" + t.getName(), e);
    log.info(name + "捕获了线程");
  }
}

